|
|
|
|
|
|
|
Solution 12
Registry Games, Part 2 |
|
|
|
|
|
|
|
|
First, let's address the problem of fixing the existing GetKeyInfo function so that it will work under Windows NT.1 The error message says that a parameter is incorrect. The best approach in cases such as this is to examine the parameters one by one. The only questionable one is the lpReserved parameter, which is described as follows: |
|
|
|
|
|
|
|
|
LPDWORD lpReserved, // reserved- Must be NULL |
|
|
|
|
|
|
|
|
What does it mean when it says that the parameter must be NULL? It means that the parameter must be 0. But what are we passing as a parameter in the GetKeyInfo function? We're passing 0, right? That's a NULL, right? |
|
|
|
|
|
|
|
|
Take a second look at the VB declaration: |
|
|
|
|
|
|
|
|
Private Declare Function RegQueryInfoKey Lib "advapi32.dll" Alias _
"RegQueryInfoKeyA" (ByVal hKey As Long, ByVal lpClass As String, _
lpcbClass As Long, lpReserved As Long, lpcSubKeys As Long, _
lpcbMaxSubKeyLen As Long, lpcbMaxClassLen As Long, lpcValues As Long, _
lpcbMaxValueNameLen As Long, lpcbMaxValueLen As Long, _
lpcbSecurityDescriptor As Long, lpftLastWriteTime As FILETIME) As Long |
|
|
|
|
|
|
|
|
lpReserved is defined By Reference. What does Visual Basic do when you pass a 0 value to a parameter that is declared By Reference as Long? |
|
|
|
|
|
|
|
|
It allocates a temporary Long variable, which it loads with the value 0. It then passes the address of that temporary variable to the function. And the address of a temporary variable is never 0! |
|
|
|
|
|
|
|
|
If you want to pass a NULL value to a function parameter of type Long, the parameter declaration must be changed to ByVal As Long. |
|
|
|
 |
|
 |
|
|
1 Curiously enough, the function works fine as shown under Windows 95 and 98, which just goes to prove how important it is that you test your applications under both operating systems. Doing your development on Windows NT will help you catch these types of errors early in the development cycle. |
|
|
|
|
|